﻿@using System.Web.Optimization
@using Smarly.Bussines.Membership
@using Smarly.Bussines.Model
@using Smarly.Web.Helpers
@model List<Smarly.Bussines.Model.Book>

@{
	bool isAdmin = User.IsInRole("Admin");
}

@section css{
	@Styles.Render("~/bundles/css/smarly-main")
	@if (isAdmin)
	{
		@Styles.Render("~/bundles/css/smarly.admin")
	}
}

@section script
{
	@Scripts.Render("~/bundles/js/smarly.main")

	@if (isAdmin)
 {
		@Scripts.Render("~/bundles/js/admin/smarly.main")
		<script type="text/javascript">
			$().ready(function() {
				$.SmarlyAdminMain({});
			});
		</script>
 }

}

@{
	ViewBag.FooterIndent = true;


	ViewBag.Title = "smarly.net библиотека";
	ViewBag.Description = string.Empty;
	ViewBag.Keywords = string.Empty;
}

@{
	var hash = Model.Random().Root.Url;
}


<div class="span12">
	<div class="book">
		@foreach (var b in Model)
		{
			<div data-hash="@b.Root.Url" class="book-content" style="@b.Root.Url.IsActive(hash, "", "display:none;")">
				<div class="wrapper">
					<div class="book-column">
						<div class="wrapper m2">
							<figure class="img-style">
								<img src="@b.CoverUrl" alt="@b.Root.Text" /></figure>
							<div class="extra-wrap">
								<h3><a href="@b.Root.Url" class="@(b.Root.Published ? "bgg" : "bgr")">@b.Root.Text</a></h3>
								<h5>@b.Author</h5>
							</div>
						</div>
						<div class="description">
							@foreach (var txt in b.Root.Children.Where(x => !x.IsHead))
							{
								@Html.Raw(txt.Text)
							}
						</div>
					</div>
					<div class="book-column">
						<h4>Оглавление</h4>
						<div class="toc">
							@{
								var headers = b.Root.Children.Where(x => x.IsHead).ToList();
								bool hasChild = headers.SelectMany(x => x.Children).Any();
							}
							<dl class="@(hasChild ? string.Empty : "no-marg")">
								@Html.Partial("_BookContentPartial", headers)
							</dl>
						</div>
					</div>
				</div>
			</div>
		}

		<ul class="thumbnails-block">
			@foreach (var b in Model)
			{
				<li class="@b.Root.Url.IsActive(hash, "active")">
					<a data-hash="@b.Root.Url">
						<img src="@b.CoverUrl" alt="@b.Root.Text" /></a>
				</li>
			}
			@if (isAdmin)
			{
				<li><a data-hash="new"><img src="/img/new-book.png" /></a></li>
			}
		</ul>

		<a id="prev" href="#"></a>
		<a id="next" href="#"></a>
	</div>
</div>

@if (isAdmin)
{
	@Html.Partial("_NewBookDialog", new Book());
}